var  RoomConstruction = new function(){
var	roomConstruction=this;
this.pass='';

this.setPass=function(pass){
 
	roomConstruction.pass=pass;
};
this.getPass=function(){
	return roomConstruction.pass;
};
 
this.joinRoom=function(roomId, roomName, usageTypeId, rangeArray) {
 
	    var room= App.get_room(roomId, 'room');
	    
	    
	    if(room) 
	      return	goToRoom(room);
	    
	    var joinRoomFunctionURL = 'http://localhost/x7/pages/joinroom.php';
       
		var argJson = {
			'room_id' : roomId,
			'roomName': roomName,
			'usageTypeId':usageTypeId,
			'rangeArray':rangeArray
		};
        
		if(RoomConstruction.getPass()){
			argJson["password"]=RoomConstruction.getPass();
        
		}
		
		$.ajax({
			type : "POST",
			url : joinRoomFunctionURL,
			dataType : "json",
			data : argJson,
			success : function(jSonRoomComponents) {

				getRoomFromPHPtoJS(jSonRoomComponents);
               
			},
			error : function(xhr, ajaxOptions, thrownError) {
				 
				alert('joinroom.js:1:' + xhr.status);
				alert(thrownError);
			}
		});

		// AJAX ICINDEN CAGRILAN FONKSIYONLAR

		var users ='';
		var messages = '';

		function getRoomFromPHPtoJS(jSonRoomComponents) {
				var url=jSonRoomComponents.url;
				if(url){
					open_content_area(url);
					return false;
				}
				
				var type=jSonRoomComponents.type;
				if(type){
					var message=jSonRoomComponents.message;
					var urlRoom=jSonRoomComponents.urlRoom;
					var navigate=jSonRoomComponents.navigate;
 					UtilJS.showMessages(type, message,navigate,urlRoom );
 					
 					return false;
				}
			    users = jSonRoomComponents.users;
				room =  new App.Room(jSonRoomComponents.room);
				messages = jSonRoomComponents.messages;
               
				room.type = 'room';
		 		
				
				
				App.add_room(room);

     		    for ( var key in users) {
					App.add_user_room(users[key], 1);
				}
	 
				for ( var key in messages) {
					var message = new App.Message(messages[key]);
					App.add_message(message);
				}
	
			 	goToRoom(room);
		}
       function goToRoom(room){
   		App.set_active_room(room);
   		close_content_area();
   		toggleUsageDiv();
        return false;
       }  
		
		}

}